package com.cmccgz.udacs_landlord_webapp.update;

import android.content.Context;
import android.os.Environment;
import android.util.DisplayMetrics;

import com.cicadamob.contact.api.Utils.ContactConfig;
import com.gmcc.gz.http_wmmp.bean.HostBean;
import com.gmcc.gz.http_wmmp.config.ConfigManager_httpwmmp;
import com.gmcc.gz.http_wmmp.config.ServerUrl_httpWmmp.HostNetype;

public class AppConfig {

    public static final String APP_CODE = "CMCCGZ_UDACS";

    public static final String localhostIp = "192.168.1.31";
    public static final String Ip73 = "183.232.32.73";
    public static final String Ip22 = "120.236.156.22";

    /**
     * 个人中心ip
     */
    private static final String PERSON_CENTER_IPPORT73 = "183.232.32.73:8181";
    private static final String PERSON_CENTER_IPPORT_SIP22 = "120.236.156.22:8181";
    private static final String PERSON_CENTER_IPPORT_localIp = PERSON_CENTER_IPPORT73
            + ":8181";
    public static final String PERSON_CENTER_IPPORT = PERSON_CENTER_IPPORT73;

    /**
     * 存储中心ip
     */
    private static final String STORAGE_IP73 = "183.232.32.73:8182";
    private static final String STORAGE_SIP_IP22 = "120.236.156.22:8182";
    private static final String STORAGE_localIp = localhostIp + ":8182";
    public static final String STORAGE_IP = STORAGE_IP73;

    // public static String WEBSERVER = localhostIp;
    public static String WEBSERVER = "183.232.32.73";
    // public static String WEBSERVER = "120.236.156.22" ;

    public static String APPUPDATE_SERVICE = com.cmccgz.udacs_landlord_webapp.base.AppConfig.getBaseUrl();

    public static final String downUrl = "http://" + STORAGE_IP
            + "/imp/mediaController/download.htm";
    public static final String uploadUrl = "http://" + STORAGE_IP
            + "/imp/mediaController/upload.htm";

    /**
     * 自维通讯录 fromid
     **/
    public static final String editContactId = "999999999";
    /**
     * 桌面启用后需要静默安装的应用
     **/
    public static final String installApkDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/dodocloud/apk/";
    /**
     * 已静默安装的应用
     **/
    public static final String installedApkDir = Environment.getExternalStorageDirectory().getAbsolutePath() + "/dodocloud/installedapk/";

    private AppConfig() {

    }

    public static final boolean DEBUG = false;

    public static final String Sp_LoginName = "Sp_LoginName";

    /**
     * 是否登陆
     **/
    public static final String Sp_Logined = "Sp_Logined";
    /*** 企业id */
    public static final String Sp_EcId = "Sp_EcId";
    /**
     * 旧的手机号
     **/
    public static final String Sp_OlderPhone = "Sp_OlderPhone";
    /**
     * 百度推送channelid
     **/
    public static final String Sp_BaiduChannelId = "Sp_BaiduChannelId";
    /**
     * 百度推送userid
     **/
    public static final String Sp_BaiduUserlId = "Sp_BaiduUserlId";
    /**
     * socketpush ip
     **/
    public static final String Sp_socketPushIP = "Sp_socketPushIP";
    /**
     * socketpush port
     **/
    public static final String Sp_socketPushPort = "Sp_socketPushPort";
    /**
     * 用户姓名
     **/
    public static final String Sp_userName = "Sp_userName";
    /**
     * 用户声音Url
     **/
    public static final String Sp_userSoundUrl = "Sp_userSoundUrl";
    /**
     * 用户声音Url
     **/
    public static final String Sp_userSoundTime = "Sp_userSoundTime";
    // 程序数据保存目录
    public static final String HEAD_DIRECTORY = "/YunDesktop";
    public static final String DIRECTORY = Environment
            .getExternalStorageDirectory().getAbsolutePath() + HEAD_DIRECTORY;
    /**
     * 默认企业id 个人(无企业id)
     **/
    public static String DEFAULT_EC_ID = "-999998";
    /**
     * 百度地图悬浮参数
     */
    public static String BAIDUMAP_PARCELABLE = "baiDuMapParcelable";
    /**
     * 百度地图确定按钮
     */
    public static String BAIDUMAP_SUBMIT = "baiDuMapSubmit";
    /**
     * 百度地图需要要强调显示位置数目
     */
    public static String BAIDUMAP_COUNT = "baiDuMapCount";

    /**
     * 获取get domain URL
     **/
    public static final String GET_HOST_URL = "GET_HOST_URL";

    /**
     * 一个广播
     */
    public static final String ContentType_ACTION = "com.gmccgz.kakaonew.Location.fragment.ContentTypeFragment";
    /**
     * 百度天气key
     **/
    public static final String BAIDU_WEATHER_KEY = "ZyclBP9q0hP8g37s9G5K33L0";


    /**
     * 用户手机号码 供robinphone 应用调用
     **/
    public static final String Sp_ROBIN_Mobile = "Sp_ROBIN_Mobile";

    public static boolean isUseYOUMENG = true;

    /**
     * 更新时间的间隔 单位毫秒
     **/
    public static final long updateTimeInterval = 30000;

    //所在城市
    public static final String sp_city = "sp_city";

    /**
     * 获取token
     *
     * @param context
     * @return
     */
    public static String getToken(Context context) {
        // return SharedPreferencesUtil.getString(context, Sp_Token,"");
        return ConfigManager_httpwmmp.getToken(context);
    }

    /**
     * getSDcardCachePath
     *
     * @param context
     * @return
     */
    public static String getSDcardCachePath(Context context) {
        return context.getExternalCacheDir().getAbsolutePath();
    }

    /**
     * 获取登陆手机号码
     *
     * @param context
     * @return
     */
    public static String getMobile(Context context) {
        // return SharedPreferencesUtil.getString(context, Sp_Mobile,"");
        return ConfigManager_httpwmmp.getPhone(context);
    }

    /**
     * 获取百度推送channelid
     *
     * @param context
     * @return
     */
    public static String getBaiduChannelId(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_BaiduChannelId, "");
    }

    /**
     * 获取百度推送userid
     *
     * @param context
     * @return
     */
    public static String getBaiduUserId(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_BaiduUserlId, "");
    }

    /**
     * 获取imei
     *
     * @param context
     * @return
     */
    public static String getIMEI(Context context) {
        // return SharedPreferencesUtil.getString(context, Sp_IMEI,"");
        return ConfigManager_httpwmmp.getIMEI(context);
    }

    /**
     * 获取IMSI
     *
     * @param context
     * @return
     */
    public static String getIMSI(Context context) {
        // return SharedPreferencesUtil.getString(context, Sp_IMSI,"");
        String imsi = ConfigManager_httpwmmp.getIMSI(context);
//		if (TextUtils.isEmpty(imsi)) {
//			TelephonyManager tm = (TelephonyManager) context
//					.getSystemService(Context.TELEPHONY_SERVICE);
//			imsi = tm.getSubscriberId();
//		}
        return imsi;
    }

    /**
     * 是否已经登陆
     *
     * @return
     */
    public static boolean isLogined(Context mContext) {
        return SharedPreferencesUtil.getBoolean(mContext, AppConfig.Sp_Logined,
                false);
    }

    /**
     * 设置是否登陆
     *
     * @param mContext
     * @param isLogined
     */
    public static void setLogined(Context mContext, boolean isLogined) {
        SharedPreferencesUtil.putBoolean(mContext, AppConfig.Sp_Logined,
                isLogined);
    }

    /**
     * 获取企业id
     *
     * @param context
     * @return
     */
    public static String getEc_id(Context context) {
        String ec_id = "";
        ec_id = SharedPreferencesUtil
                .getString(context, Sp_EcId, DEFAULT_EC_ID);
        return ec_id;
    }

    /**
     * 注销的时候清空企业id
     *
     * @param context
     */
    public static void clear_Ec_id(Context context) {
        SharedPreferencesUtil.getString(context, Sp_EcId, DEFAULT_EC_ID);
    }

    /**
     * 保存socket_push ip和port
     *
     * @param context
     * @param ip
     * @param port
     */
    public static void saveSocketPushIpAndPort(Context context, String ip,
                                               int port) {
        SharedPreferencesUtil.putString(context, Sp_socketPushIP, ip);
        SharedPreferencesUtil.putInt(context, Sp_socketPushPort, port);

    }

    /**
     * 获取socket_push ip
     *
     * @param context
     * @return
     */
    public static String getSocketPushIp(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_socketPushIP, "");
    }

    /**
     * 获取sockt_push port
     *
     * @param context
     * @return
     */
    public static int getSocketPushPort(Context context) {
        return SharedPreferencesUtil.getInt(context, Sp_socketPushPort, 0);
    }

    /**
     * 设置各模块网元的ip和port netype：网元类型， 包括如下取值 socket：socket组件 imp：消息中心 ctrl：控制平台
     * contact：通讯录 storage：存储中心 group：群组 task：任务 information：资讯
     * <p>
     * <p>
     * 如不需要做保存处理 可直接通过 ConfigManager_httpwmmp.getHostUrl(context, HostNetype.类型)
     * 获取相应的ip/port
     */
    public static void setHostDomain(Context context) {
        HostBean bean = new HostBean();
        String ip = "";
        int port = 0;
        // 1、控制平台
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.ctrl);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl();// http:// ip : port;
        // todo something
        // 临时用 等后台配置好后 删除
        ConfigManager_httpwmmp.saveCtrlHostUrl(context,
                ServerUrl.Ctrl_host_host);

        // 2、socket组件
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.socket);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // 保存ip/port
        saveSocketPushIpAndPort(context, ip, port);

        // 3、消息中心
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.imp);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // to do something

        // 4、通讯录
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.contact);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // to do something

        ContactConfig.setConfigIp(AppConfig.WEBSERVER, "8181");

        // 5、存储中心
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.media);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // to do something

        // 6、 ：群组
        bean = ConfigManager_httpwmmp.getHostUrl(context, HostNetype.group);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // to do something

        // 7、：任务
        // bean=ConfigManager_httpwmmp.getHostUrl(context, HostNetype.task);
        // ip=bean.getIP();
        // port=bean.getPort();
        // bean.getHostUrl(); // http:// ip : port;
        // to do something

        // 8、：工作圈
        bean = ConfigManager_httpwmmp.getHostUrl(context,
                HostNetype.work);
        ip = bean.getIP();
        port = bean.getPort();
        bean.getHostUrl(); // http:// ip : port;
        // to do something
    }

    /**
     * 获取用户姓名
     *
     * @param context
     * @return
     */
    public static String getUserName(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_userName, "");
    }

    /**
     * 保存用户姓名
     *
     * @param context
     * @param userName
     */
    public static void saveUserName(Context context, String userName) {
        SharedPreferencesUtil.putString(context, Sp_userName, userName);
    }

    /**
     * 获取用户媒体声音url
     *
     * @param context
     * @return
     */
    public static String getUserSoundUrl(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_userSoundUrl, "");
    }

    /**
     * 保存用户媒体声音URL
     *
     * @param context
     * @param userName
     */
    public static void saveUserSoundUrl(Context context, String userName) {
        SharedPreferencesUtil.putString(context, Sp_userSoundUrl, userName);
    }

    /**
     * 获取用户媒体声音时长
     *
     * @param context
     * @return
     */
    public static String getUserSoundTime(Context context) {
        return SharedPreferencesUtil.getString(context, Sp_userSoundTime, "");
    }

    /**
     * 保存用户媒体声音时长
     *
     * @param context
     * @param userName
     */
    public static void saveUserSoundTime(Context context, String userName) {
        SharedPreferencesUtil.putString(context, Sp_userSoundTime, userName);
    }

    /**
     * 保存获取 domain url
     *
     * @param context
     * @param url
     */
    public static void saveGetHostUrl(Context context, String url) {
        SharedPreferencesUtil.putString(context, GET_HOST_URL, url);
    }

    /**
     * 获取 domain url
     *
     * @param context
     * @return
     */
    public static String getHostUrl(Context context) {
        return SharedPreferencesUtil.getString(context, GET_HOST_URL, "");

    }


    /**
     * 保存robin phone 电话号码
     *
     * @param context
     * @return
     */
    public static void saveRobinMobile(Context context) {
        // return SharedPreferencesUtil.getString(context, Sp_Mobile,"");
        SharedPreferencesUtil.putString(context, Sp_ROBIN_Mobile, getMobile(context));
    }

    /**
     * 注销时清除robin phone 电话号码
     *
     * @param context
     */
    public static void clearRobinMobin(Context context) {
        SharedPreferencesUtil.putString(context, Sp_ROBIN_Mobile, "");
    }

    /**
     * 判断是否为9.7寸话机
     *
     * @return
     */
    public static boolean deviceIsBigScreen(Context context) {
        DisplayMetrics dm2 = context.getResources().getDisplayMetrics();
        int screenWidth = dm2.widthPixels;
        int screenHeight = dm2.heightPixels;
//        ToastUtils.show(context, "whith:" + screenWidth + ",height:" + screenHeight);
        return screenWidth == 1024 && screenHeight == 768;
    }
}
